<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Section 4.3.1: Compute and display the Chebyshev center of a 2D polyhedron</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/cvxbook/Ch04_cvx_opt_probs/html/chebyshev_center_2D.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Section 4.3.1: Compute and display the Chebyshev center of a 2D polyhedron</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#plots">Plots</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Boyd &amp; Vandenberghe, "Convex Optimization"</span>
<span class="comment">% Jo&euml;lle Skaf - 08/16/05</span>
<span class="comment">% (a figure is generated)</span>
<span class="comment">%</span>
<span class="comment">% The goal is to find the largest Euclidean ball (i.e. its center and</span>
<span class="comment">% radius) that lies in a polyhedron described by linear inequalites in this</span>
<span class="comment">% fashion: P = {x : a_i'*x &lt;= b_i, i=1,...,m} where x is in R^2</span>

<span class="comment">% Generate the input data</span>
a1 = [ 2;  1];
a2 = [ 2; -1];
a3 = [-1;  2];
a4 = [-1; -2];
b = ones(4,1);

<span class="comment">% Create and solve the model</span>
cvx_begin
    variable <span class="string">r(1)</span>
    variable <span class="string">x_c(2)</span>
    maximize ( r )
    a1'*x_c + r*norm(a1,2) &lt;= b(1);
    a2'*x_c + r*norm(a2,2) &lt;= b(2);
    a3'*x_c + r*norm(a3,2) &lt;= b(3);
    a4'*x_c + r*norm(a4,2) &lt;= b(4);
cvx_end

<span class="comment">% Generate the figure</span>
x = linspace(-2,2);
theta = 0:pi/100:2*pi;
plot( x, -x*a1(1)./a1(2) + b(1)./a1(2),<span class="string">'b-'</span>);
hold <span class="string">on</span>
plot( x, -x*a2(1)./a2(2) + b(2)./a2(2),<span class="string">'b-'</span>);
plot( x, -x*a3(1)./a3(2) + b(3)./a3(2),<span class="string">'b-'</span>);
plot( x, -x*a4(1)./a4(2) + b(4)./a4(2),<span class="string">'b-'</span>);
plot( x_c(1) + r*cos(theta), x_c(2) + r*sin(theta), <span class="string">'r'</span>);
plot(x_c(1),x_c(2),<span class="string">'k+'</span>)
xlabel(<span class="string">'x_1'</span>)
ylabel(<span class="string">'x_2'</span>)
title(<span class="string">'Largest Euclidean ball lying in a 2D polyhedron'</span>);
axis([-1 1 -1 1])
axis <span class="string">equal</span>
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Calling Mosek 9.1.9: 4 variables, 3 equality constraints
   For improved efficiency, Mosek is solving the dual problem.
------------------------------------------------------------

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:32:15)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: MACOSX/64-X86

Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : LO (linear optimization problem)
  Constraints            : 3               
  Cones                  : 0               
  Scalar variables       : 4               
  Matrix variables       : 0               
  Integer variables      : 0               

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries                  : 2                 time                   : 0.00            
Lin. dep.  - tries                  : 1                 time                   : 0.00            
Lin. dep.  - number                 : 0               
Presolve terminated. Time: 0.00    
Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : LO (linear optimization problem)
  Constraints            : 3               
  Cones                  : 0               
  Scalar variables       : 4               
  Matrix variables       : 0               
  Integer variables      : 0               

Optimizer  - threads                : 8               
Optimizer  - solved problem         : the primal      
Optimizer  - Constraints            : 3
Optimizer  - Cones                  : 0
Optimizer  - Scalar variables       : 4                 conic                  : 0               
Optimizer  - Semi-definite variables: 0                 scalarized             : 0               
Factor     - setup time             : 0.00              dense det. time        : 0.00            
Factor     - ML order time          : 0.00              GP order time          : 0.00            
Factor     - nonzeros before factor : 6                 after factor           : 6               
Factor     - dense dim.             : 0                 flops                  : 6.20e+01        
ITE PFEAS    DFEAS    GFEAS    PRSTATUS   POBJ              DOBJ              MU       TIME  
0   6.0e+00  0.0e+00  8.5e+00  0.00e+00   4.000000000e+00   0.000000000e+00   2.9e+00  0.00  
1   1.3e+00  4.4e-16  1.9e+00  1.74e+00   9.333165808e-01   2.492631633e-01   6.4e-01  0.01  
2   3.5e-02  8.9e-16  5.0e-02  3.09e+00   4.532518544e-01   4.456360007e-01   1.8e-02  0.01  
3   4.8e-06  8.9e-16  6.9e-06  1.02e+00   4.472144123e-01   4.472134243e-01   2.5e-06  0.01  
4   4.8e-10  8.9e-16  6.9e-10  1.00e+00   4.472135956e-01   4.472135955e-01   2.5e-10  0.01  
Basis identification started.
Primal basis identification phase started.
Primal basis identification phase terminated. Time: 0.00
Dual basis identification phase started.
Dual basis identification phase terminated. Time: 0.00
Basis identification terminated. Time: 0.00
Optimizer terminated. Time: 0.02    


Interior-point solution summary
  Problem status  : PRIMAL_AND_DUAL_FEASIBLE
  Solution status : OPTIMAL
  Primal.  obj: 4.4721359558e-01    nrm: 1e+00    Viol.  con: 2e-10    var: 0e+00  
  Dual.    obj: 4.4721359548e-01    nrm: 4e-01    Viol.  con: 0e+00    var: 2e-18  

Basic solution summary
  Problem status  : PRIMAL_AND_DUAL_FEASIBLE
  Solution status : OPTIMAL
  Primal.  obj: 4.4721359550e-01    nrm: 1e+00    Viol.  con: 1e-17    var: 0e+00  
  Dual.    obj: 4.4721359548e-01    nrm: 4e-01    Viol.  con: 0e+00    var: 0e+00  
Optimizer summary
  Optimizer                 -                        time: 0.02    
    Interior-point          - iterations : 4         time: 0.01    
      Basis identification  -                        time: 0.00    
        Primal              - iterations : 1         time: 0.00    
        Dual                - iterations : 0         time: 0.00    
        Clean primal        - iterations : 0         time: 0.00    
        Clean dual          - iterations : 0         time: 0.00    
    Simplex                 -                        time: 0.00    
      Primal simplex        - iterations : 0         time: 0.00    
      Dual simplex          - iterations : 0         time: 0.00    
    Mixed integer           - relaxations: 0         time: 0.00    

------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.447214
 
</pre>
<a id="plots"></a>
<div id="plotoutput">
<img src="chebyshev_center_2D__01.png" alt=""> 
</div>
</div>
</body>
</html>